Skip to content

Proxy MCP client name in local stdio server User-Agent#304

Merged
keshavc-stripe merged 3 commits intostripe:mainfrom
mvanhorn:osc/250-proxy-mcp-client-name-user-agent
Mar 18, 2026
Merged

Proxy MCP client name in local stdio server User-Agent#304
keshavc-stripe merged 3 commits intostripe:mainfrom
mvanhorn:osc/250-proxy-mcp-client-name-user-agent

Conversation

@mvanhorn
Copy link
Contributor

Summary

Extracts the MCP client name from the initialize request and includes it in the User-Agent header sent to mcp.stripe.com. When Cursor connects, the header reads stripe-mcp-local/0.3.1 (cursor) instead of the static stripe-mcp-local/0.3.1.

Changes

  • Deferred HTTP transport creation: The HTTP transport is now created on the first stdio message instead of upfront. This lets us inspect the initialize message for clientInfo.name before building headers.
  • extractClientName(): Parses a JSONRPCMessage and returns the client name if the message is an initialize request with clientInfo.
  • buildUserAgent(): Appends the client name in parentheses to the base user agent string.
  • Tests: 6 new test cases covering client name extraction (Cursor, Claude Desktop, missing clientInfo, non-initialize messages, responses, notifications) and User-Agent formatting.

All messages are still forwarded unchanged - the proxy only peeks at the first message for metadata.

Testing

All CI checks pass locally:

  • pnpm run build - clean
  • pnpm run lint - clean
  • pnpm run prettier-check - clean
  • pnpm run test - 17/17 passing (6 new + 11 existing)

Fixes #250

This contribution was developed with AI assistance (Claude Code).

Extract the client name from the MCP initialize request and include it
in the User-Agent header sent to mcp.stripe.com. When a client like
Cursor or Claude Desktop connects, the User-Agent now reads
"stripe-mcp-local/0.3.1 (cursor)" instead of just "stripe-mcp-local/0.3.1".

The HTTP transport creation is deferred until the first stdio message
arrives, so the client name from the initialize request can be captured
before any HTTP requests are made.

Fixes stripe#250
@cla-assistant
Copy link

cla-assistant bot commented Mar 15, 2026

CLA assistant check
All committers have signed the CLA.

@cla-assistant
Copy link

cla-assistant bot commented Mar 15, 2026

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Move extractClientName and buildUserAgent into userAgent.ts so tests
don't transitively import the MCP SDK's streamableHttp transport, which
pulls in pkce-challenge (ESM-only) and breaks Jest in CI.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Committed-By-Agent: claude
Copy link
Collaborator

@matv-stripe matv-stripe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

quick question

}
return BASE_USER_AGENT;
}
export {extractClientName, buildUserAgent};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to reexport here?

@keshavc-stripe
Copy link
Contributor

Testing:
echo '{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"npx-inspector","version":"1.0.0"}}}' | node dist/index.js --api-key=YOUR_KEY

Run that from tools/modelcontextprotocol/

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Committed-By-Agent: claude
@keshavc-stripe keshavc-stripe merged commit ac8fdfa into stripe:main Mar 18, 2026
5 checks passed
@mvanhorn
Copy link
Contributor Author

Thanks for the review and merge!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

proxy mcp client name in the local mcp stdio server

3 participants